local qizhou = fk.CreateSkill{
    name = "gai__qizhou",
    tags = { Skill.Compulsory },  -- 锁定技
}

Fk:loadTranslationTable{
    ["gai__qizhou"] = "绮胄",
    [":gai__qizhou"] = "锁定技，游戏开始时，你获得两张副类别各不同的装备牌并置入装备区。你根据装备区里牌的花色数获得以下技能：1种以上-〖英姿〗；2种以上-〖破军〗；3种以上-〖澜江〗；4种-〖奋威〗。",

    ["$ex__yingzi_gai__heqi"] = "人靠衣装马靠鞍！",
    ["$pojun_gai__heqi"] = "可真是一把好刀啊！",
    ["$fenwei_gai__heqi"] = "我的船队，要让全建业城的人都看见！",
    ["$lanjiang_gai__heqi"] = "大江惊澜，浪涌四极之疆！",
}

local function QizhouChange(player, num, skill_name)
    local room = player.room
    local skills = player.tag[qizhou.name] or {}
    local suits = {}
    for _, e in ipairs(player:getCardIds("e")) do
        table.insertIfNeed(suits, Fk:getCardById(e).suit)
    end
    table.removeOne(suits, Card.NoSuit)
    if #suits >= num then
        if not table.contains(skills, skill_name) then
            room:handleAddLoseSkills(player, skill_name, nil, false, true)
            table.insert(skills, skill_name)
        end
    else
        if table.contains(skills, skill_name) then
            room:handleAddLoseSkills(player, "-"..skill_name, nil, false, true)
            table.removeOne(skills, skill_name)
        end
    end
    player.tag[qizhou.name] = skills
end

-- 游戏开始时获得装备
qizhou:addEffect(fk.GameStart, {
    anim_type = "drawcard",
    can_trigger = function(self, event, target, player, data)
        return player:hasSkill(qizhou.name)
    end,
    on_cost = Util.TrueFunc,
    on_use = function(self, event, target, player, data)
        local room = player.room
        local equipMap = {}
        for _, id in ipairs(room.draw_pile) do
            local sub_type = Fk:getCardById(id).sub_type
            if Fk:getCardById(id).type == Card.TypeEquip and player:canMoveCardIntoEquip(id, false) then
                local list = equipMap[tostring(sub_type)] or {}
                table.insert(list, id)
                equipMap[tostring(sub_type)] = list
            end
        end
        local sub_types = {}
        for k, _ in pairs(equipMap) do
            table.insert(sub_types, k)
        end
        sub_types = table.random(sub_types, 2)
        local cards = {}
        for _, sub_type in ipairs(sub_types) do
            table.insert(cards, table.random(equipMap[sub_type]))
        end
        if #cards > 0 then
            room:moveCardIntoEquip(player, cards, qizhou.name, false, player)
        end
    end,
})

-- 失去技能时移除所有获得的技能
qizhou:addEffect(fk.EventLoseSkill, {
    is_delay_effect = true,
    can_trigger = function (self, event, target, player, data)
        return target == player and data.name == qizhou.name and #(player.tag[qizhou.name] or {}) > 0
    end,
    on_use = function (self, event, target, player, data)
        local skills = player.tag[qizhou.name]
        player.room:handleAddLoseSkills(player, "-"..table.concat(skills, "|"), nil, false, true)
        player.tag[qizhou.name] = nil
    end,
})

-- 装备区变化时更新技能
qizhou:addEffect(fk.AfterCardsMove, {
    can_refresh = function(self, event, target, player, data)
        if player:hasSkill(qizhou.name) then
            for _, move in ipairs(data) do
                if move.to == player and move.toArea == Card.PlayerEquip then
                    return true
                end
                if move.from == player then
                    for _, info in ipairs(move.moveInfo) do
                        if info.fromArea == Card.PlayerEquip then
                            return true
                        end
                    end
                end
            end
        end
    end,
    on_refresh = function(self, event, target, player, data)
        QizhouChange(player, 1, "ex__yingzi")
        QizhouChange(player, 2, "re__pojun")
        QizhouChange(player, 3, "lanjiang")
        QizhouChange(player, 4, "fenwei")
    end,
})

return qizhou